package com.jingxing.provider;

import org.apache.commons.lang3.StringUtils;

/**
 * @author han
 * @title: MatchInfoMapperProvider
 * @date 2021/9/16 14:50
 */
public class MatchInfoMapperProvider {

    public String getMatchInfos(Integer competitionLevel, String name, String phone){
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT\n" +
                "\tm.*,\n" +
                "\tp.`name` AS playerName,\n" +
                "\tp.gender AS gender,\n" +
                "\tp.photo_url AS photoUrl,\n" +
                "\tp.phone_number AS phoneNumber ");
        sql.append("FROM\n" +
                "\tmatch_info AS m\n" +
                "\tINNER JOIN player_user_info AS p ON m.player_id = p.id ");
        sql.append("WHERE\n" +
                "\tm.del = 0 \n" +
                "\tAND p.del = 0\n" +
                "\tand m.competition_level = " + competitionLevel + " ");
        if (StringUtils.isNotBlank(name)) {
            sql.append("AND p.`name` = '" + name + "' ");
        }
        if (StringUtils.isNotBlank(phone)) {
            sql.append("AND p.phone_number = '" + phone + "' ");
        }
        sql.append("ORDER BY m.rating DESC ");
        return sql.toString();
    }


}
